﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Private.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>
<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Utility" %>
<asp:Content ID="Content2" ContentPlaceHolderID="TitleHolder" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
    <script type="text/javascript">
        function ApprovedCustomer(requestingId, requestedId, value) {
            var ff = document.getElementById("FriendLoader");
            var dataString = "requestingId=" + requestingId + "&requestedId=" + requestedId + "&Decision=" + value;
            $.ajax({
                type: "POST",
                url: "/Friend/MakeFriend",
                data: dataString,
                beforeSend: function (xhm) {
                    ff.innerHTML = "<img src='..Content/Images/fb_loader.gif'/>"
                },
                success: function (result) {
                    var object = jQuery.parseJSON(result);
                    var resultString;
                    resultString += "<table><tr>";
                    for (var i = 0; i < object.length; i++) {
                        resultString += "<td>";
                        resultString += "<div style='width: 100px; height: 100px' ><img style='width: 100px; height: 100px' src='/../Content/Images/Upload/" + object[i]["MemAvatar"] + "' alt=''/></div>";
                        resultString += "<div><strong>" + object[i]["MemFullname"] + "</strong></div>";
                        resultString += "<div> <input type='image' style='width:20px;height:20px' src='/../Content/Images/friend_ok.png' onclick=\"ApprovedCustomer(" + requestingId + "," + object[i]["MemId"] + ",'A')\"/>";
                        resultString += " <input type='image' style='width:20px;height:20px' src='/../Content/Images/friend_cancle.png' onclick=\"RejectedCustomer(" + requestingId + "," + object[i]["MemId"] + ",'R')\"/>";
                        resultString += "<input type='image' style='width:20px;height:20px' src='/../Content/Images/friend_block.png' onclick=\"BlockedCustomer(" + requestingId + "," + object[i]["MemId"] + ",'B')\"/>"
                        resultString += "</div></td>";
                        if ((i + 1) % 5 == 0) {
                            resultString += ("</tr>");
                            resultString += ("<tr>");
                        }

                    }
                    resultString += ("</tr>");
                    resultString += ("</table>");
                    //location.reload(true);
                    var memFriendList = document.getElementById("MemFriendList");
                    var MemFriendCount = document.getElementById("MemFriendCount");
                    var innerText = MemFriendCount.innerText;
                    var currentFriend = innerText.split(" ");
                    MemFriendCount.innerHTML = parseInt(currentFriend[0]) + 1 + " bạn";
                    memFriendList.innerHTML = resultString;


                    $.ajax({
                        type: "POST",
                        url: "/Friend/MakeFriendUpdate",
                        data: "requestingId=" + requestingId,
                        success: function (result) {
                            var object2 = jQuery.parseJSON(result);
                            var resultString2;
                            resultString2 += "<table><tr>";
                            for (var i = 0; i < object2.length; i++) {
                                resultString2 += "<td>";
                                //                                resultString2+="<a href='{0}'>", Url.RouteUrl("PrivateDefaultRoute", new { uid = hot.MemId, isEditMode = false })));
                                resultString2 += "<div style='width: 70px; height: 70px' ><img style='width: 70px; height: 70px' src='/../Content/Images/Upload/" + object2[i]["MemAvatar"] + "' alt=''/></div>";
                                resultString2 += "<div style='width:70px'><strong>" + object2[i]["MemFullname"] + "</strong></div>";
                                resultString2 += " </div></td>";
                                if ((i + 1) % 3 == 0) {
                                    resultString2 += ("</tr>");
                                    resultString2 += ("<tr>");
                                }
                            }
                            resultString2 += ("</tr>");
                            resultString2 += ("</table>");
                            //location.reload(true);
                            var MemFriendListHome = document.getElementById("MemFriendListHome");
                            MemFriendListHome.innerHTML = resultString2;
                        },
                        error: function (req, status, error) {
                            alert("Sorry! We could not receive your feedback at this time.");
                        }
                    });
                    ff.innerHTML = "";
                },
                error: function (req, status, error) {
                    alert("Sorry! We could not receive your feedback at this time.");
                }
            });
        }

        function BlockedCustomer(requestingId, requestedId, value) {
            var ff = document.getElementById("FriendLoader");
            var dataString = "requestingId=" + requestingId + "&requestedId=" + requestedId + "&Decision=" + value;
            $.ajax({
                type: "POST",
                url: "/Friend/MakeFriend",
                data: dataString,
                beforeSend: function (xhm) {
                    ff.innerHTML = "<img src='../Content/Images/fb_loader.gif />'";
                },
                success: function (result) {
                    alert("Block thành công !");
                    ff.innerHTML = "";
                    location.reload(true);
                },
                error: function (req, status, error) {
                    alert("Sorry! We could not receive your feedback at this time.");
                }
            });
        }

        function RejectedCustomer(requestingId, requestedId, value) {
            var ff = document.getElementById("FriendLoader");
            var dataString = "requestingId=" + requestingId + "&requestedId=" + requestedId + "&Decision=" + value;
            $.ajax({
                type: "POST",
                url: "/Friend/MakeFriend",
                data: dataString,
                beforeSend: function (xhm) {
                    ff.innerHTML = "<img src='../Content/Images/fb_loader.gif/>'";
                },
                success: function (result) {
                    ff.innerHTML = "false";
                    alert("Từ chối thành công !");
                    location.reload(true);
                },
                error: function (req, status, error) {
                    alert("Sorry! We could not receive your feedback at this time.");
                }
            });
        }
     
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentHolder" runat="server">
    <%
        var hMem = (MemberHelper)ViewData["hMem"];
    %>
    <div class="private_rightbottom_content">
        <div class="private_rightbottom_contentleft">
            <div class="private_share_post">
                <div class="private_share_post_top">
                    <div class="private_sharepost_menu">
                        <ul>
                            <li>
                                <%= Html.ActionLink("Bạn bè", "EmailService", "Friend", new { uid = hMem.Member.MemId }, new { @id = "private_menu_friend" })%></li>
                            <li><a href="#" class="menu_select">Khách mời kết bạn</a></li>
                        </ul>
                    </div>
                    <div class="private_write_right">
                        <div class="private_bt_newspost">
                            <a href="vietbai_private.html">
                                <img src="/../Content/Images/icon_newpost.gif">
                                Viết bài mới... </a>
                        </div>
                    </div>
                </div>
                <div id="FriendLoader">
                </div>
                <div class="private_comment_top" id="MemFriendList">
                    <%List<Member> pendingMember = new FriendHelper().getAllPendingMembers(hMem.Member.MemId);
                      int count = 0;
                    %>
                    <% Response.Write("<table>");
                       Response.Write("<tr>");
                       foreach (Member mem in pendingMember)
                       {
                           count++;
                           Response.Write("<td>");
                    %>
                    <div style="width: 100px; height: 100px">
                        <img style="width: 100px; height: 100px" src="/../Content/Images/Upload/<%=mem.MemAvatar %>"
                            alt="" />
                    </div>
                    <div>
                        <strong>
                            <%=mem.MemFullname%></strong>
                    </div>
                    <div>
                        <input type="image" style="width: 20px; height: 20px" src="/../Content/Images/friend_ok.png"
                            onclick="ApprovedCustomer(<%=hMem.Member.MemId %>,<%=mem.MemId%>,'A')" />
                        <input type="image" style="width: 20px; height: 20px" src="/../Content/Images/friend_cancle.png"
                            onclick="RejectedCustomer(<%=hMem.Member.MemId %>,<%=mem.MemId%>,'R')" />
                        <input type="image" style="width: 20px; height: 20px" src="/../Content/Images/friend_block.png"
                            onclick="BlockedCustomer(<%=hMem.Member.MemId %>,<%=mem.MemId%>,'B')" />
                    </div>
                    <%
                        Response.Write("</td>");
                        if (count % 5 == 0)
                        {
                            Response.Write("</tr>");
                            Response.Write("<tr>");
                        }
                       } Response.Write("</tr>");
                       Response.Write("</table>");
                    %>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
